package org.devocean.groupbuying.web.frontend;

import java.util.ArrayList;
import java.util.List;

import org.devocean.groupbuying.domain.Explored;
import org.devocean.groupbuying.domain.Merchant;
import org.devocean.groupbuying.service.ExploredService;
import org.devocean.groupbuying.service.MerchantService;
import org.devocean.groupbuying.service.ProductService;
import org.devocean.groupbuying.web.frontend.displaybeans.ExplorerBean;
import org.devocean.groupbuying.web.frontend.displaybeans.MerchantBean;
import org.devocean.groupbuying.web.frontend.displaybeans.ProductBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = { "/{lang:[a-z]{2}}/clouds/merchants" })
public class MerchantController {

	@Autowired
	MerchantService merchantService;
	
	
	@Autowired
	ExploredService exploredService;
	
	@RequestMapping("{merchantID}")
	public String getMerchantById(@CookieValue("clientLanguage") String lang,
			@PathVariable Integer merchantID,ModelMap map){
		List<ExplorerBean> explorerBeans = new ArrayList<ExplorerBean>();
		MerchantBean merchantBean = new MerchantBean(merchantService.getMerchantById(merchantID));
		map.put("merchant", merchantBean);
		for (Explored ex : exploredService.getExploredByMerchants(merchantID, lang)) {
			explorerBeans.add(new ExplorerBean(ex));
		}
		map.put("explorerBeans", explorerBeans);
		return "merchant";
	}
	
}
